#ifndef SDLWINDOW_H
#define SDLWINDOW_H

#include "common.h"

int W =  512;

int sdl_print_bpp()
{
	const SDL_VideoInfo* vi;
	const SDL_PixelFormat* pf;
	vi = SDL_GetVideoInfo();
	if(!vi)
		sdl_error();
	pf = vi->vfmt;
	printf("we need bpp 32, check what we have\n");
	printf("bpp %d\n", pf->BitsPerPixel);
	return 1;
}

int sdl_preset_opengl()
{
	if(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8))
		sdl_error();
    if(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8))
    	sdl_error();
    if(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8))
    	sdl_error();
    if(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16))
    	sdl_error();
    if(SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1))
    	sdl_error();
    return 1;
}

int sdl_create_window()
{
	if(SDL_Init(SDL_INIT_VIDEO))
		sdl_error();
	sdl_print_bpp();
	sdl_preset_opengl();
	SDL_WM_SetCaption("Tanks", 0);
    if (!SDL_SetVideoMode(W, W, 32, SDL_OPENGL 
		/*| SDL_NOFRAME*/))
    	sdl_error();
    
	return 1;
}

#endif
